<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }
        
        .box input {
            width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }
        
        .box img {
            position: absolute;
            top: 2px;
            right: 2px;
            width: 24px;
        }
    </style>
</head>

<body>
    <div class="box">
        <!-- <label for="">
            <img src="../images/close.jpg" alt="" id="eye">
        </label> -->
        <input type="password" id="psw">
    </div>
    <script>
        // 1.获取元素
        var eye = document.getElementById('eye');
        var pwd = document.getElementById('pwd');
        // 2.注册事件 处理程序
        var flag = 0;
        eye.onclick = function() {
            //点击以此之后 flag 要发生变化 0就是闭眼  1就是睁眼
            if (flag == 0) {
                pwd.type = 'text';
                // eye.src = '.. / images / close.jpg ';
                flag = 1; //重新赋值 下一次就变成1 进入else
            } else {
                pwd.type = 'password' // 密码框 就是看不见的 ****
                    // eye.src = '.. / images / open.jpg';
                flag = 0; //这里重新赋值 下次进入 if 那个步骤
            }
        }
    </script>
</body>

</html>